package cn.zwxky.android.staff.Jurisdiction.Technology;

import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.zgscwjm.lsfbbasetemplate.Event.EventAnnotation;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.OnClick;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.config.Config;
import com.zgscwjm.lsfbbasetemplate.internet.BaseInternet;
import com.zgscwjm.lsfbbasetemplate.utils.DensityUtils;
import com.zgscwjm.lsfbbasetemplate.utils.SN;
import com.zgscwjm.lsfbbasetemplate.utils.T;

import java.util.HashMap;

import cn.zwxky.android.staff.Login.ForgetBean;
import cn.zwxky.android.staff.R;
import cn.zwxky.android.staff.Utils.LittleUtils;
import cn.zwxky.android.staff.Utils.NoDoubleClickUtils;
import cn.zwxky.android.staff.Utils.URLString;

/**
 * 技术部发布任务
 * Created by Administrator on 2017/3/31 0031.
 */
@ContentView(R.layout.aty_release_task)
public class TechnologyReleaseTaskActivity extends LsfbActivity {

    @ViewInject(R.id.aty_release_task_et_import)
    private EditText et_import;

    @ViewInject(R.id.aty_leave_add_img_select)
    private SimpleDraweeView img_select;

    private String id;

    private String select_id = "";
    private String select_img = "";

    private Handler handler = new Handler() {
        @Override
        public void dispatchMessage(Message msg) {
            super.dispatchMessage(msg);
            switch (msg.what) {
                case 1000:
                    img_select.setImageURI(Uri.parse(URLString.IMG_URL + select_img));
                    break;
            }
        }
    };

    @Override
    public void initView() {
        LittleUtils.setsimpletitlebar(this, "发布任务");
        TextView textView = new TextView(this);
        textView.setText("发送");
        textView.setTextColor(getResources().getColor(R.color.white_color));
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //收起软键盘
                if (!NoDoubleClickUtils.isDoubleClick()) {
                    post();
                }

            }
        });
        getTitleBar().setRightView(textView, 0, 0, DensityUtils.dp2px(this, 10), 0);

        id = getIntent().getStringExtra("id");

    }

    @Override
    public void initEvent() {

    }

    /**
     * 点击事件
     *
     * @param view
     */
    @OnClick({R.id.aty_leave_add_img_select})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.aty_leave_add_img_select:
                startActivity(new Intent(this, TaskAlloActivity2.class));
                break;
        }
    }

    @Override
    public void initData() {

    }

    public void post() {


        if (select_id.isEmpty()) {
            SN.SnackShow(et_import, "请选择接收人");
            return;
        }

        if (et_import.getText().toString().isEmpty()) {
            SN.SnackShow(et_import, "请输入任务内容");
            return;
        }

        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("uid", Config.getUserId());
        hashMap.put("sid", id);
        hashMap.put("content", et_import.getText().toString());
        hashMap.put("people", select_id);
        new BaseInternet().getData(URLString.TASKPUB, hashMap, ForgetBean.class, new TechnologyReleaseTaskPostEvent<ForgetBean>(), false);
    }

    @EventAnnotation
    public void TechnologyReleaseTaskPostEvent(TechnologyReleaseTaskPostEvent<ForgetBean> event) {
        switch (event.getCode()) {
            case 200:
                T.showShort(this, event.getMsg());
                finish();
                break;
            default:
                SN.SnackShow(et_import, event.getMsg());
                break;
        }
    }

    @EventAnnotation
    public void TaskAlloClickEvent4(TaskAlloClickEvent4 event) {
        select_id = event.getData().getId();
        select_img = event.getData().getImg();
        handler.sendEmptyMessage(1000);
    }

}
